//function

users = [
  ["id":1,"name":"jenkins1"],
  ["id":2,"name":"jenkins2"], 
  ["id":3,"name":"jenkins3"]
]

pipeline{
  agent any // 修正了这里的拼写
  stages{
    stage("run"){
      steps{
        script{
          //调用函数
          name = GetUserNameById(1)
          println "User name is ${name}" //jenkins1
        }
      }
    }
  }
}

def GetUserNameById(id){
  for(user in users){
    if(user.id == id){
      return user.name
    }
  }
  return "User not found"
}
